# -*- Makefile -*-
#
# Makefile.PSP - Makefile rules for Sony Play Station Portable Firmware version 1.0
#   Thanks Shiikuru-san
#

PSPPRE = $(shell psp-config --psp-prefix)
PSPDEV = $(shell psp-config --pspdev-path)
PSPSDK = $(shell psp-config --pspsdk-path)

INCS  = $(shell $(PSPPRE)/bin/sdl-config --cflags) $(shell $(PSPPRE)/bin/freetype-config --cflags)
LIBS  = $(shell $(PSPPRE)/bin/sdl-config --libs)
LIBS += -lSDL_ttf -lSDL_image -lSDL_mixer -lSDL -lSDLmain -lfreetype -lbz2 -lm -ljpeg -lpng -lz -lmad -lvorbisidec

# Include PSPSDK and Libc Headers
INCS += -I$(PSPSDK)/include -I$(PSPDEV)/include -I$(PSPPRE)/include

# Link PSPSDK and Libc Libraries
LIBS += -L$(PSPSDK)/lib -L$(PSPDEV)/lib -lstdc++ -lpspsdk -lpspgu -lpspdebug -lpspdisplay -lpsphprm -lpspaudio -lpspge -lpspctrl -lc -lpspnet_inet -lpspuser -lpspkernel -lpsppower


# Build as PRX, if needed
#LIBS += -specs=$(PSPSDK)/lib/prxspecs -Wl,-q,-T$(PSPSDK)/lib/linkfile.prx


# with OggVorbis (Tremor) in PDA size (QVGA)
#DEFS = -DPSP -DPDA -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS
# with OggVorbis (Tremor) in PSP size (360x270)
DEFS = -DPSP -DPDA -DPDA_WIDTH=360 -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS
# with OggVorbis (Tremor) in PSP size (384x288)
#DEFS = -DPSP -DPDA -DPDA_WIDTH=384 -DBPP16 -DMP3_MAD -DUSE_OGG_VORBIS -DINTEGER_OGG_VORBIS

# PSP FW Version
DEFS += -D_PSP_FW_VERSION=150
#DEFS += -D_PSP_FW_VERSION=371

# 1-byte char
DEFS += -DENABLE_1BYTE_CHAR

EXESUFFIX = .elf
OBJSUFFIX = .o

.SUFFIXES:
.SUFFIXES: $(OBJSUFFIX) .cpp .h

CC = psp-gcc 
LD = psp-gcc -o
CP = ln -s

CFLAGS = -g -G0 -O3 -Wall -Wpointer-arith -fno-exceptions -fno-rtti -fno-check-new -pipe -c $(INCS) $(DEFS)
RM = rm -f

TARGET = EBOOT.PBP
EXT_OBJS = MadWrapper$(OBJSUFFIX)


# onscripter.elf -> EBOOT.PBP for PSP Firmware version 1.0

FIXUP_IMPORTS = psp-fixup-imports
STRIP         = psp-strip
MKSFO         = mksfo
PACK_PBP      = pack-pbp

PSP_TARGET       = onscripter$(EXESUFFIX)
PSP_TARGET_FIXUP = onscripter_fixup$(EXESUFFIX)
PSP_TARGET_STRIP = onscripter_strip$(EXESUFFIX)
PSP_EBOOT_TITLE  = ONScripter for PSP
PSP_EBOOT_SFO    = PARAM.SFO
PSP_EBOOT_ICON   = pspicon/ICON0.PNG
PSP_EBOOT_ICON1  = NULL
PSP_EBOOT_UNKPNG = NULL
PSP_EBOOT_PIC1   = pspicon/PIC1.PNG
PSP_EBOOT_SND0   = NULL
PSP_EBOOT_PSAR   = NULL

EBOOT.PBP : $(PSP_TARGET_STRIP) $(PSP_EBOOT_SFO)
	$(PACK_PBP) EBOOT.PBP $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON)  \
		$(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1)  \
		$(PSP_EBOOT_SND0)  $(PSP_TARGET_STRIP) $(PSP_EBOOT_PSAR)

$(PSP_EBOOT_SFO) :
	$(MKSFO) '$(PSP_EBOOT_TITLE)' $(PSP_EBOOT_SFO)

$(PSP_TARGET_FIXUP) : $(PSP_TARGET)
	$(FIXUP_IMPORTS) $(PSP_TARGET) -o $(PSP_TARGET_FIXUP)

$(PSP_TARGET_STRIP) : $(PSP_TARGET_FIXUP)
	$(STRIP) $(PSP_TARGET_FIXUP) -o $(PSP_TARGET_STRIP)

include Makefile.onscripter

# overriding
clean :
	$(RM) $(TARGET)
	$(RM) $(PSP_TARGET) $(PSP_TARGET_FIXUP) $(PSP_TARGET_STRIP) $(PSP_EBOOT_SFO)
	$(RM) *.o
	$(RM) onslocale.cpp
